﻿using System.IO;
using System.Threading;
using GHIElectronics.NETMF.FEZ;
using GHIElectronics.NETMF.Hardware;
using GHIElectronics.NETMF.IO;
using Microsoft.SPOT.IO;
using System.Text;
using NetMf.CommonExtensions;
using Microsoft.SPOT.Hardware;
using FEZ_Panda_II_Application1;
using System.IO.Ports;
using Microsoft.SPOT;
using System;
using System.Diagnostics;

public class Program
{
    
    static FileStream FileHandle;

    public static string rootDirectory = "";
    static SerialPort UART = new SerialPort("COM1", 19200);

    public static void Main()
    {
        UART.Open();
        Print("Starting up");

        
        PersistentStorage sdPS = new PersistentStorage("SD");

        sdPS.MountFileSystem();
        rootDirectory = VolumeInfo.GetVolumes()[0].RootDirectory;
        

        Print("SD initialized");

        FlightControl.Init(rootDirectory);
        Sensors s = new Sensors(rootDirectory);
        Boom b = new Boom();
        PowerControl p = new PowerControl();
        s.HighSpeedRead();

    }

    public static void Print(string str)
    {
        str = DateTime.Now.Ticks + ":" + str + "\r\n";
        var data=Encoding.UTF8.GetBytes(str);
        UART.Write(data, 0, data.Length);
#if DEBUG
            Debug.Print(str);
#endif
        if (rootDirectory == "") { return; }
        File.WriteAllBytes(Path.Combine(rootDirectory, "log.txt"), data);
    }
    
 
}

